function validate() {
    $("#formEdit")
        .validate(
        {
            rules : {
                'name' : {
                    required: true
                }

            }
        });
}

$(document).ready(function(){
    var table = document.getElementById('table_speciality');
    table.rows[table.rows.length - 1].children[3].children[0].style.display = ''
});

function addRowSpecialty(tableID) {
    var table = document.getElementById(tableID);
    contadorParaNuevasFilas++;
    var counts = contadorParaNuevasFilas;

    var rowSpeciality = $('#table_speciality tbody>tr:last').clone()[0];

    rowSpeciality.children[0].children[0].innerText='';
    rowSpeciality.children[1].children[0].name = "therapeuticArea.specialities["+counts+"].name";
    rowSpeciality.children[1].children[0].value = "";

    table.rows[table.rows.length - 1].children[3].children[0].style.display = 'none';
    $('#table_speciality tbody').append(rowSpeciality);
}

function deleteRow(tableID, button) {

    var table = document.getElementById(tableID);
    if(table.rows.length == 2){
        var row = table.rows[1];
        row.cells[0].children[0].value = "";
    }else{
        var rowIndex = button.parentNode.parentNode.rowIndex;
        if(rowIndex == 1){
            $('#table_speciality tr').each(function(index, row){
                if(index < (table.rows.length -1)){
                    row.children[1].children[0].value = table.rows[index + 1].children[1].children[0].value;
                }
            });
            rowIndex = table.rows.length - 1;
        }
        table.deleteRow(rowIndex);
        table.rows[table.rows.length - 1].children[3].children[0].style.display = '';
    }
}